package com.cskaoyan.service;


import com.cskaoyan.bean.user.Address;
import com.cskaoyan.bean.user.AddressExample;
import com.cskaoyan.mapper.AddressMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dww
 */
@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    private AddressMapper addressMapper;

    public List<Address> getAddressList(Integer page, Integer limit, String sort, String order, String name, Integer userId) {
        PageHelper.startPage(page, limit, sort + " " + order);
        AddressExample example = new AddressExample();
        AddressExample.Criteria criteria = example.createCriteria();
        if (name != null)
            criteria.andNameLike("%" + name + "%");
        if (userId != null)
            criteria.andUserIdEqualTo(userId);
        return addressMapper.selectByExample(example);
    }


}
